package com.audaque.springboot.foshanupload.mpj.injector;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
import com.github.yulichang.injector.MPJSqlInjector;

import java.util.List;

/**
 * @author zgb
 * @desc ...
 * @date 2023-04-03 20:50:45
 */
public class DiyMpjSqlInjector extends MPJSqlInjector {


    public DiyMpjSqlInjector() {

    }



    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo ) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass,tableInfo);
        //更新时自动填充的字段，不用插入值
        methodList.add(new InsertBatchSomeColumn(i -> {
            boolean result = true;
            if (i.getFieldFill() == FieldFill.UPDATE) {
                result = false;
            }

            return result;

        }));

        methodList.add(new AlwaysUpdateSomeColumnById());
        methodList.add(new LogicDeleteByIdWithFill());

        return methodList;
    }
}
